﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace DraggableWindow
{
    public static class ControlExtensions
    {
        /// <summary>
        /// Returns the cordinates you would have to use to center this control on <paramref name="parentElement"/>
        /// </summary>
        /// <param name="ourElement">You</param>
        /// <param name="parentElement">Your parent</param>
        /// <returns>The top left cords to set your element to</returns>
        public static Point GetCenteredCords(this FrameworkElement ourElement, FrameworkElement parentElement)
        {
            Point center = new Point()
            {
                X=0.5d *(parentElement.ActualWidth - ourElement.ActualWidth),
                Y=0.5d * (parentElement.ActualHeight - ourElement.ActualHeight)
            };

            return center;
        }


        public static Size GetMaxSize(this UIElement ourElement, Size resultSize, Size availableSize)
        {

            resultSize.Width = Math.Max(resultSize.Width, ourElement.DesiredSize.Width);
            resultSize.Height = Math.Max(resultSize.Height, ourElement.DesiredSize.Height);

            //resultSize.Width = double.IsPositiveInfinity(availableSize.Width) ?
            //    resultSize.Width : availableSize.Width;

            //resultSize.Height = double.IsPositiveInfinity(availableSize.Height) ?
            //    resultSize.Height : availableSize.Height;
            return resultSize;
        }
    }
}
